'''
#作用域转换
sum_up = 10
def sum(a,b):
    #global sum_up
    sum_up = a + b
    print ("sum_up=",sum_up)
sum(10,20)
print("sum_up=",sum_up)

def value():
    a = 5
    def value_2():
        nonlocal a
        a = 3
        print (a)
    value_2()
    print(a)
value()

#计时器
import time
def clock_time_deco(func):
    def wrapper(*arg,**kwargs):
        start_time = time.time()
        result = func(*arg,**kwargs)
        end_time = time.time()
        print(f"{func.__name__}耗时：{format(end_time - start_time,'.2f')}s")
        return result
    return wrapper

@clock_time_deco
def foo(a,b):
    count = 1
    while True:
        if count > a**b:
            break
        count +=1

foo(12,5)
'''
#fibo缓存
def cache_deco(func):
    global a
    a = {}
    def wrapper(n):
        if n in a:
            pass
        else:
            a[n] = func(n)
        return a[n]
    return wrapper

@cache_deco
def fibo(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    else:
        return fibo(n-1)+fibo(n-2)

fibo(5)
print(a)
